/**
 * 
 */
package com.hd123.rumba.qt.report;

import net.sf.jasperreports.engine.JRVariable;

public class FieldDefinition {
  /**
   * 列标题
   */
  String title;
  /**
   * 打印宽度
   */
  int MINWIDTH = 10;
  int width = MINWIDTH;
  /**
   * 字段名称 Select语句的字段名称. 对ORACLE, 全部为大写.
   */
  String name;
  /**
   * 值类型 Integer.class, Double.class, String.class, Date.class等
   */
  Class valueClass;
  /**
   * 显示格式 #,##0.00, yyyy-MM-dd等
   */
  String pattern;
  /**
   * 合计
   */
  String gAggregation;

  public String getTitle() {
    return title;
  }

  public void setTitle(String caption) {
    this.title = caption;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getWidth() {
    return width;
  }

  public void setWidth(int width) {
    if (width > MINWIDTH)
      this.width = width;
  }

  public Class getValueClass() {
    return valueClass;
  }

  public void setValueClass(Class valueClass) {
    this.valueClass = valueClass;
  }

  public String getPattern() {
    return pattern;
  }

  public void setPattern(String pattern) {
    this.pattern = pattern;
  }

  public String getGAggregation() {
    return gAggregation;
  }

  public void setGAggregation(String aggregation) {
    gAggregation = aggregation;
  }

  public byte getGAggregationCalculation() {
    if ("SUM".equals(gAggregation))
      return JRVariable.CALCULATION_SUM;
    else if ("MAX".equals(gAggregation))
      return JRVariable.CALCULATION_HIGHEST;
    else if ("MIN".equals(gAggregation))
      return JRVariable.CALCULATION_LOWEST;
    else if ("COUNT".equals(gAggregation))
      return JRVariable.CALCULATION_COUNT;
    else if ("COUNTDISTINCT".equals(gAggregation))
      return JRVariable.CALCULATION_DISTINCT_COUNT;
    else if ("AVG".equals(gAggregation))
      return JRVariable.CALCULATION_AVERAGE;
    else
      return JRVariable.CALCULATION_NOTHING;
  }
}
